/*
 * @Author: Li
 * @Date: 2022-04-03 13:44:52
 * @LastEditors: Li
 * @LastEditTime: 2022-04-03 18:14:00
 * @Description: 
 */
// https://api.apidoc.doyzheng.com/user/get
// https://api.apidoc.doyzheng.com/project/list
// https://api.apidoc.doyzheng.com/project/join-list
// https://api.apidoc.doyzheng.com/category/list
// https://api.apidoc.doyzheng.com/dictionary/detail
// https://api.apidoc.doyzheng.com/api/list

// yl-cli config set account 19137804785;
// yl-cli config set password li111111;
// yl-cli doc module(班课练习) catagroy(订单) update;

const HOST = 'https://apidoc.doyzheng.com';
const PATH_LOGIN = 'login/account';
import axios from 'axios';
import { LocalStorage } from "node-localstorage";
const localStorage = new LocalStorage('./scratch');

function login() {
    const account = localStorage.getItem('account');
    const password = localStorage.getItem('password');
    console.log('账号:' + account);
    console.log('密码:' + password);
    console.log('路径:' + `${HOST}/${PATH_LOGIN}`);

    axios.post(`${HOST}/${PATH_LOGIN}`, {
        account: account,
        password: password
      })
      .then(({code, data, msg}) => {
        console.log(code, data, msg);
      })
      .catch((err) => {
        console.error(err);
      });
}

function update() {

}

function cache(key, value) {
    if (value) {
        localStorage.setItem(key, value);
    } else {
        return localStorage.getItem(key);
    }
}

function command(cmds, path) {
    console.log('指令:  ' +  cmds);
    console.log('代码执行的路径:  ' + path);
    if (cmds.length <= 0) {
      return;
    }
    const type = cmds.shift();
    if (type === 'config') {
      const key = cmds.shift();
      if (key === undefined) {
        console.warn('请输入键');
        return;
      }
      const val = cmds.shift();
      if (val !== undefined) {
        localStorage.setItem(key, val);
      } else {
        console.log(key, localStorage.getItem(key));
      }
    } else if (type === 'doc') {
      if (type === 'doc') {

      }
    } else if (type === 'login') {
      login();
    } else {
      console.log('该指令不存在');
    }
}

export {
    command
}
